package com.example.studentmanager.db;


import com.example.studentmanager.db.entity.Student;

public class StudentManager {
    private static Student LOGIN_USER;

    public static Student getLoginStudent() {
        if (LOGIN_USER == null) {
            LOGIN_USER = MyDBHelper.getInstances().isLogin();
        }
        return LOGIN_USER;
    }

    public static boolean isLogin() {
        Student loginStudent = getLoginStudent();
        return loginStudent != null && loginStudent.isLogin();
    }

    public static boolean login(String name, String password) {
        return MyDBHelper.getInstances().login(name, password);
    }

    public static boolean logout() {
        if (LOGIN_USER != null) {
            if (MyDBHelper.getInstances().logout(LOGIN_USER)) {
                LOGIN_USER = null;
                return true;
            }
        }
        return false;
    }

    public static boolean isExistsStudent(String username) {
        return MyDBHelper.getInstances().isExistsStudent(username);
    }

    public static boolean registerStudent(String username, String password, String name, String clazz, String numberId) {
        return MyDBHelper.getInstances().registerStudent(username, password, name, clazz, numberId);
    }

}
